package com.febers.ihealth.fragment

import android.view.View
import com.febers.ihealth.R
import com.febers.ihealth.base.BaseFragment
import com.febers.ihealth.entity.ReleaseNextSurveyEvent
import com.febers.ihealth.utils.Event
import com.febers.ihealth.utils.user
import kotlinx.android.synthetic.main.survey_chuhan.*

class SurveyChuhan: BaseFragment() {

    private var checked = false

    override fun setView(): Int = R.layout.survey_chuhan

    override fun initView() {
        if (user.fare) {
            radio_group_fare_han?.visibility = View.VISIBLE
            radio_group_bufare_han?.visibility = View.GONE
            radio_group_fare_han?.setOnCheckedChangeListener { group, checkedId ->
                user.clearChuhan()
                when(checkedId) {
                    R.id.radio_button_wuhan -> user.wuhan = true
                    R.id.radio_button_weihan -> user.weihan = true
                    R.id.radio_button_zhengchanghan -> user.zhengchanghan = true
                    R.id.radio_button_baitianhan -> user.baitianhan = true
                    R.id.radio_button_yejianhan -> user.yejianhan = true
                }
                checked = true
                Event.post(ReleaseNextSurveyEvent(true))
            }
        } else {
            radio_group_bufare_han?.visibility = View.VISIBLE
            radio_group_fare_han?.visibility = View.GONE
            radio_group_bufare_han?.setOnCheckedChangeListener { group, checkedId ->
                user.clearChuhan()
                when(checkedId) {
                    R.id.radio_button_bufare_zhengchanghan -> user.zhengchanghanBufare = true
                    R.id.radio_button_no_bufare_baitianhan -> user.baitianhanBufare = true
                    R.id.radio_button_bufare_yejianhan -> user.yejianhanBufare = true
                }
                checked = true
                Event.post(ReleaseNextSurveyEvent(true))
            }
        }
    }

    override fun lazyInit() {
    }

    override fun onVisible() {
        Event.post(ReleaseNextSurveyEvent(false))
        if (checked) {
            Event.post(ReleaseNextSurveyEvent(true))
        }
    }
}